package com.xunker.user.controller;

import com.xunker.appointment.result.Result;
import org.apache.commons.codec.net.URLCodec;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.util.UriEncoder;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

@Controller
@RequestMapping("api/aliyun")
public class AliyunLoginController {
    /**
     * 阿里云沙箱测试登录
     */
    @GetMapping("aliyunLogin")
    @ResponseBody
    public Result aliyunLogin() throws UnsupportedEncodingException {
        String appid="2021000117691200";
        String redirect_uri="http://127.0.0.1:8150/api/aliyun/callback";
        redirect_uri= URLEncoder.encode(redirect_uri,"utf-8");
        String redirect_url="https://openauth.alipaydev.com/oauth2/publicAppAuthorize.htm?app_id="+appid+"&scope=auth_user&redirect_uri="+redirect_uri;
        return Result.ok(redirect_url);
    }

    @GetMapping("aliyunLoginTest")
    public String aliyunLoginTest() throws UnsupportedEncodingException {
        String appid="2021000117691200";
        String redirect_uri="http://127.0.0.1:8150/api/aliyun/callback";
        redirect_uri= URLEncoder.encode(redirect_uri,"utf-8");
        String redirect_url="https://openauth.alipaydev.com/oauth2/publicAppAuthorize.htm?app_id="+appid+"&scope=auth_user&redirect_uri="+redirect_uri;
        return "redirect:"+redirect_url;
    }
    @RequestMapping("callback")
    @ResponseBody
    public String callback(){

        return "ok";
    }
}
